<?php
ob_start();
//201201/10
$timeDir = date("Ym")."/".date("d");
$pathAbs = dirname(__FILE__).'/upload/'.$timeDir;
$curDomain = "http://".$_SERVER["HTTP_HOST"]."/";
//相对路径 http://www.ncmem.com/upload/2012-1-10/
$relatPath = $curDomain ."up2/upload/" . $timeDir . "/";

//自动创建目录。upload/2012-1-10
if(!is_dir($pathAbs))
{
	mkdir($pathAbs,0777,true);
}

$nameSvr = $_FILES['file']['name'];
$nameTmp = $_FILES['file']['tmp_name'];

//取文件扩展名jpg,gif,bmp,png
$path_parts = pathinfo($fileName);
$ext = $path_parts["extension"];
$ext = strtolower($ext);//jpg,png,gif,bmp

$pathSvr = $pathAbs . "/" . $nameSvr;

//另存为新文件名称
if (!move_uploaded_file($nameTmp,$pathSvr))
{
	exit('upload error!' . "文件名称：" .$fileName . "保存路径：" . $savePath);
}

//输出图片路径
//$_SERVER['HTTP_HOST']	localhost:81
//$_SERVER['REQUEST_URI'] /FCKEditor2.4.6.1/php/test.php 
$reqPath = str_replace("upload.php","",$_SERVER['REQUEST_URI']);
echo $relatPath .  $nameSvr;
header('Content-type: text/html; charset=utf-8');
header('Content-Length: ' . ob_get_length());
?>